package servlet;

import com.alibaba.fastjson.JSON;
import domain.ResultInfo;
import domain.User;
import mapper.UserMapper;
import utils.MapperUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/user/findByUid")
public class FindByUidServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        String uid = request.getParameter("uid");
        UserMapper userMapper = MapperUtil.getMapper(UserMapper.class);
        User byUid = userMapper.findByUid(Integer.parseInt(uid));
        ResultInfo resultInfo = new ResultInfo();
            resultInfo.setStatus(1);
            resultInfo.setMsg("查询成功");
            resultInfo.setData(byUid);
        response.getWriter().write(JSON.toJSONString(resultInfo));
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}